package com.sun.hunk.hibernate.domain.impl;

import com.sun.hunk.hibernate.domain.Role;
import com.sun.hunk.hibernate.domain.User;
import com.sun.hunk.hibernate.domain.UserRole;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author sunil
 */
@Entity
@Table(name = "user_role")
public class UserRoleImpl implements UserRole {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=UserImpl.class)
    private User userId;
    @JoinColumn(name = "role_id", referencedColumnName = "id")
    @ManyToOne(targetEntity=RoleImpl.class)
    private Role roleId;

    public UserRoleImpl() {
    }

    public UserRoleImpl(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public User getUserId() {
        return userId;
    }

    public void setUserId(User userId) {
        this.userId = userId;
    }

    public Role getRoleId() {
        return roleId;
    }

    public void setRoleId(Role roleId) {
        this.roleId = roleId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserRoleImpl)) {
            return false;
        }
        UserRoleImpl other = (UserRoleImpl) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.cong.logiware.hibernate.domain.UserRole[id=" + id + "]";
    }

}
